<template>
  <div style=" width: 60%; margin: 0 auto;">
    <div class="container">
      <div class="movie-card  wow animate__zoomIn" v-for="(item,index) of list" :key="index">
        <img class="movie-poster" :src='`${item.movie.mimg}`' alt="电影海报">
        <div class="movie-info">
          <div class="movie-title">{{ item.movie.mname }}</div>
          <div class="movie-rating">

            <div class="rank">{{ item.movie.mgrade }}</div>
          </div>
          <button class="unfavorite-btn" @click="handleCancel(item.movie.id)">取消收藏</button>
        </div>
      </div>
      <!--      <div class="poster-container wow animate__zoomIn" v-for="(item,index) of list" :key="index">-->
      <!--        <div class="poster" @click="handleMovieDetail(item.movie)" :style="{backgroundImage: `url(${item.movie.mimg})`}">-->
      <!--          <div class="label">{{ item.movie.mname }}</div>-->
      <!--          <div class="rank">{{ item.movie.mgrade }}</div>-->
      <!--        </div>-->
      <!--        <button class="buy-button" @click="handleCancel(item.movie.id)">取消收藏</button>-->
      <!--      </div>-->
    </div>
    <el-pagination
        v-if="list.length!==0"
        style="margin: 20px 30px"
        small
        layout="prev, pager, next"
        :page-size="page.pageSize"
        @current-change="handlePage"
        :total="total">
    </el-pagination>
  </div>
</template>

<script>
import requests from "@/api/request";
import wow from 'wow.js'

export default {
  name: "FavoriteMovie",
  data() {
    return {
      page: {
        pageNo: 1,
        pageSize: 12
      },
      list: [],
      total: 0
    }
  },
  methods: {
    async init() {
      const promise = await this.$baseApi.callGetMethod("getLikeMovie", {
        id: this.$store.state.user.uid,
        pageNo: this.page.pageNo,
        pageSize: this.page.pageSize
      });
      if (promise.data.code === 200) {
        this.list = promise.data.data.list
        this.total = promise.data.data.total
      } else {
        this.$message.error(this.promise.msg)
      }
    },
    handleCancel(mid) {
      this.$confirm('是否确定取消收藏？', '系统提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        cancelButtonClass: 'btn-custom-cancel',
        type: 'warning'
      }).then(() => {
        requests({
          method: 'post',
          url: '/api/AddFavorite',
          params: {uid: this.$store.state.user.uid, mid: mid, type: 'del'}
        }).then((response) => {
          if (response.data.isError) {
            this.$message.error(response.data.message)
          } else {
            this.$message.success(response.data.message)
            this.init()
          }
        })
      })
    },
    handlePage(newNo) {
      this.page.pageNo = newNo
      this.init()
    },
    handleMovieDetail(movie) {
      this.$store.state.movie = movie
      this.$router.push({name: 'MovieDetail'})
    },
  },
  mounted() {
    new wow().init()
    this.init()

  },
}
</script>

<style scoped>
.container {
  display: grid;
  grid-template-columns: repeat(auto-fill, 180px);
  grid-gap: 10px;
  justify-content: center;

}


.text-overlay p {
  margin: 0;
  font-size: 24px;
  font-weight: bold;
  line-height: 1.2;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.7);
}

.movie-card {
  position: relative;
  width: 170px;
  height: 270px; /* 增加高度以容纳底部按钮 */
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
  font-family: 'Arial', sans-serif;
  transition: transform 0.3s;
}

.movie-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.3);
}

.movie-poster {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s;
}

.movie-card:hover .movie-poster {
  transform: scale(1.05);
}

.movie-info {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 15px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.9));
  color: white;
}

.movie-title {
  font-size: 18px;
  font-weight: bold;
  margin-bottom: 8px;
  text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.8);
  white-space: nowrap;         /* 禁止换行 */
  overflow: hidden;           /* 隐藏超出部分 */
  text-overflow: ellipsis;    /* 超出显示省略号 */
}

.movie-rating {
  display: flex;
  align-items: center;
  margin-bottom: 12px;
}

.rating-stars {
  color: #FFD700;
  margin-right: 8px;
  font-size: 14px;
}

.rating-value {
  font-weight: bold;
  font-size: 14px;
}

.unfavorite-btn {
  width: 100%;
  padding: 8px 0;
  background-color: #ff4757;
  color: white;
  border: none;
  border-radius: 4px;
  font-weight: bold;
  cursor: pointer;
  transition: background-color 0.3s;
}

.unfavorite-btn:hover {
  background-color: #ff6b81;
}
</style>